import Vue from 'vue'
import Vuex from 'vuex'
import axios from "axios"
Vue.use(Vuex)

export default new Vuex.Store({
  state: {
      arr:[]
  },
  mutations: {
      setArr(state,payload){
            state.arr = payload
      },
      addArr(state,payload){
        state.arr = [...state.arr,...payload]
  },

  },
  // action 是写异步函数的
  actions: {
      getList({commit,state},payload){
            axios.get("/list").then(res=>{
                console.log(res.data)
                commit("setArr",res.data)
            })
      },
     addList({commit,state},payload){
        axios.get("/addList").then(res=>{
            console.log(res.data)
            commit("addArr",res.data)
        })
     }
  },
  modules: {
  }
})
